<template>
	<MescrollUni top="1" :down="downOption" @down="downCallback"
	 :up="upOption" @up="upCallback" class="scroll-box">
		<view class="wish-box" v-for="item in dataList" :key="item.group_id" @click="goDetail(item)">
			<user-header :info="item"></user-header>
			<text class="wish-content">
				{{item.my_wish}}
			</text>
			<product-item :info="item" rightText="帮TA分享" @right-click="showSharePopup(item)" class="li-product"></product-item>
		</view>
		<share-popup :groupId="selGroupId" @init="initShareInfo" :visible.sync="sharePopupVisible"></share-popup>
	</MescrollUni>
</template>

<script>
	import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
	import SharePopup from '@/components/share-popup.vue'
	import ProductItem from "@/components/product/item.vue"
	import UserHeader from "@/components/user/header.vue"
	// #ifdef MP-WEIXIN
	import ShareMixin from '@/mixins/share-mixin.js'
	// #endif
	export default {
		// #ifdef MP-WEIXIN
		mixins: [ShareMixin],
		// #endif
		components: {
			MescrollUni,
			SharePopup,
			ProductItem,
			UserHeader
		},
		data() {
			return {
				dataList:[],
				downOption: {
					autoShowLoading:true,
					use: true
				},
				upOption: {
					use: true, // 是否启用上拉加载; 默认true
					auto: true,
					onScroll: true,
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					}
				},
				sharePopupVisible: false,
				selGroupId:false
			};
		},
		methods:{
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			showSharePopup(item){
				this.selGroupId=item.group_id
				this.sharePopupVisible = true
			},
			goDetail(item){
				uni.navigateTo({
					url:`/pages/wish/detail?group_id=${item.group_id}`
				})
			},
			upCallback(mescroll) {
				let page = mescroll.num // 页码, 默认从1开始
				let pageSize = mescroll.size // 页长, 默认每页10条
				this.$api.getSupportList({state:this.activeTab,page,page_size:pageSize},{loading:false}).then(
					res=>{
						if(mescroll.num == 1) this.dataList = []; //如果是第一页需手动置空列表
						this.dataList = this.dataList.concat(res)
						mescroll.endSuccess(res.length)
					},
					()=>{
						mescroll.endErr()
					}
				)
			},
		}
	}
</script>

<style lang="scss">
page{
	background-color: #F6F6F6;
	border-top:1rpx solid #F0F0F0;
}
.wish-box{
	margin-bottom: 20rpx;
	padding:40rpx 36rpx;
	background-color: #fff;
}
.wish-content{
	font-size:30rpx;
	color:#333;
}
</style>
